<template>
  <div class="page-content">
    <table-bar :showTop="false" :columns="columns" @changeColumn="changeColumn">
      <div slot="top">
        <el-form
          :model="searchForm"
          :rules="rules"
          label-width="100px"
          ref="searchForm"
        >
          <el-row :gutter="20">
            <el-col :xs="24" :sm="12" :lg="6">
              <form-input
                label="搜索"
                @input="change($event)"
                v-model="searchForm.keyword"
                prop="keyword"
                placeholder="电商单号/出库单号/客户名称"
                @keyup.enter.native="submitForm('searchForm')"
              ></form-input>
            </el-col>
            <el-row
              :xs="24"
              :sm="12"
              :lg="6"
              style="float: left;margin-right: 10px;"
            >
              <el-button type="primary" @click="submitForm('searchForm')"
                >搜索</el-button
              >
              <el-button @click="resetForm('searchForm')">重置</el-button>
            </el-row>
          </el-row>
        </el-form>
      </div>
    </table-bar>
    <div class="order-table">
      <k-table
        :data="tableData"
        v-loading="loading"
        ref="shopcarttable"
        @sortHandler="sort($event)"
        :page="setpage"
        :total="setpage.total"
        @changePage="gotopage($event)"
        @changeSize="gotosize($event)"
      >
        <el-table-column type="index" width="50" fixed="left">
        </el-table-column>
        <div v-for="(item, index) in tableHeader" :key="index">
          <el-table-column
            :prop="item.name"
            :label="item.title"
            show-overflow-tooltip
            sortable="custom"
            :width="
              item.name === 'writedate'
                ? '180'
                : item.name === 'ddpaper'
                ? '200'
                : item.name === 'ckpaper'
                ? '200'
                : item.name === 'guestname'
                ? '200'
                : ''
            "
          >
          </el-table-column>
        </div>
      </k-table>
    </div>
  </div>
</template>

<script>
import { getPayListApi } from "@/api/orderApi";
export default {
  inject: ["reload"],
  data() {
    return {
      tableData: [],
      tableHeader: [],
      tableBody: [],
      columns: [],
      gridDataHeader: [],
      loading: true,
      title: "",
      gridData: [],
      showEmptyTips: true,
      searchForm: {
        keyword: ""
      },
      setpage: {
        page: 1,
        pageSize: 10,
        total: 0
      },
      rules: {
        keyword: [{ required: true, message: "请输入关键词", trigger: "blur" }]
      }
    };
  },
  mounted() {
    this.getPayListData("", "", 1);
  },
  methods: {
    getPayListData(prop, order, pageindex) {
      let userdata = JSON.stringify(this.$store.state.user.user.info);
      userdata = JSON.parse(userdata);
      let guestcode = userdata.reguserno;
      let gscode = userdata.gscode;
      let username = userdata.userName;
      let userid = userdata.id;
      let logintype = userdata.logintype;
      let posttype = userdata.posttype;
      let sort = "";
      if (order != undefined && order.length > 0 && order != null) {
        if (order == "ascending") {
          sort = prop + " asc ";
        } else if (order == "descending") {
          sort = prop + " desc ";
        }
      }
      getPayListApi({
        guestcode: guestcode,
        gscode: gscode,
        sort: sort,
        username: username,
        userid: userid,
        menuename: "CustomerPayList",
        menucname: "客户支付流水",
        logintype: logintype,
        posttype: posttype,
        pagesize: this.setpage.pageSize,
        pageindex: pageindex,
        op_type: "查询"
      }).then(res => {
        this.loading = false;
        this.tableHeader = [];
        this.tableData = [];
        this.setpage.total = res.count;
        res.filesName.forEach(element => {
          if (element.hidden === false) {
            this.tableHeader.push({ title: element.title, name: element.name });
            this.columns.push({ name: element.title, show: true });
          }
        });
        res.data.forEach(element => {
          this.tableData.push({
            writedate: element.writedate,
            ordertype: element.ordertype,
            ddpaper: element.ddpaper,
            ckpaper: element.ckpaper,
            guestname: element.guestname,
            paytype: element.paytype,
            total: parseFloat(element.total).toFixed(2),
            paystate: element.paystate,
            paytime: element.paytime,
            ramount: parseFloat(element.ramount).toFixed(2)
          });
        });
      });
    },
    sort(val) {
      this.getPayListData(val.prop, val.order);
    },
    gotopage(val) {
      this.getPayListData("", "", val.page);
    },
    clear() {
      this.gridDataHeader = [];
      this.gridData = [];
    },
    refresh() {
      this.reload();
    },
    change(e) {
      this.$forceUpdate();
    },
    changeColumn(columns) {
      this.columns = columns;
      this.doLayout();
    },
    doLayout() {
      this.$nextTick(() => {
        this.$refs.shopcarttable.doLayout();
      });
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          let userdata = JSON.stringify(this.$store.state.user.user.info);
          userdata = JSON.parse(userdata);
          let guestcode = userdata.reguserno;
          let gscode = userdata.gscode;
          getPayListApi({
            guestcode: guestcode,
            gscode: gscode,
            keyword: this.searchForm.keyword
          }).then(res => {
            this.loading = false;
            this.tableHeader = [];
            this.columns = [];
            this.tableData = [];
            this.setpage.total = res.count;
            res.filesName.forEach(element => {
              if (element.hidden === false) {
                this.tableHeader.push({
                  title: element.title,
                  name: element.name
                });
                this.columns.push({ name: element.title, show: true });
              }
            });
            res.data.forEach(element => {
              this.tableData.push({
                writedate: element.writedate,
                ddpaper: element.ddpaper,
                ckpaper: element.ckpaper,
                guestname: element.guestname,
                paytype: element.paytype,
                total: parseFloat(element.total).toFixed(2),
                paystate: element.paystate,
                paytime: element.paytime,
                ramount: parseFloat(element.ramount).toFixed(2)
              });
            });
          });
        } else {
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.getPayListData("", "", 1);
    }
  }
};
</script>

<style lang="scss">
.page-content {
  width: 100%;
  height: 100%;
}
.order-table-expand {
  font-size: 0;
}
.order-table-expand label {
  width: 90px;
  color: #2d8cf0;
}
.order-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
.order-table {
  height: 100% !important;

  // 分页组件
  ::v-deep .el-pagination {
    margin: 20px 0 0 -5px;
    padding-left: 0;
  }

  // 滚动条
  ::v-deep ::-webkit-scrollbar {
    height: 6px !important;
    display: block !important;
  }

  .empty {
    i {
      color: #d7d6d6;
      font-size: 40px;
    }

    p {
      color: #999999;
      font-size: 13px;
      line-height: 30px;
      margin-top: -10px;
    }
  }
}
.hide-scroll-bar {
  ::v-deep ::-webkit-scrollbar {
    width: 0 !important;
    height: 0 !important;
  }
}
@media only screen and (max-width: $device-notebook) {
}

@media only screen and (max-width: $device-ipad) {
  // .page-content{
  //   display: none;
  // }
}
</style>
